package com.mymail.myutil;

import java.util.Iterator;

import com.mymail.dao.FolderDAO;
import com.mymail.entity.Folder;
import com.mymail.entity.User;

public class AddFolder {
	public final static String EXIST_ERROR="已存在同名文件夹！";
	public final static String ADD_OK="OK";
	public static String add(String foldername,String folderother,User user){
		if(isExist(foldername, user))return EXIST_ERROR;
		Folder folder=new Folder();
		folder.setName(foldername);
		folder.setOther(folderother);
		folder.setUser(user.getId());
		FolderDAO dao=Folder.getDAO();
		dao.addNew(folder);
		user.setFolders(null);
		return ADD_OK;
	}
	public static boolean isExist(String name,User user){
		Iterator<Folder> it=user.getFolders().iterator();
		while(it.hasNext()){
			if(name.trim().equals(it.next().getName()))return true;
		}
		return false;
	}
}
